#include"drv_systick.h"
static uint16_t fs_ms;
static uint16_t fs_us;

void init_systick(uint8_t systick)
{
	SysTick->CTRL &=~0x05;//将第2位和第0位置零
	fs_us=systick/8;//因为选择了第二位为0，所以/8
	fs_ms=1000*fs_us;
}
void ms_systick(uint16_t ms)
{
	uint32_t temp=0;
	SysTick->LOAD=fs_ms*ms;
	SysTick->CTRL |=0x01;
	do
		{
		temp=SysTick->CTRL;
		}
	while (!(temp&(0x01<<16)));
	
}
void us_systick(uint16_t us)
{
	uint32_t temp=0;
	SysTick->LOAD=fs_us*us;
	SysTick->CTRL |=0x01;
	do
		{
		temp=SysTick->CTRL;
		}
	while (!((0x01<<16)&temp));
}
void delay_ms(int a)
{


	int b=0;
	int c;
	init_systick(168);
	while(a>500)
	{
		a=a-500;
		b++;
	}
	for(c=0;c<b;c++)
		{
			ms_systick(500);
		}
	ms_systick(a);
}



